fix(go-sdk): surface json.Marshal errors in memory backend requests#679
fix(go-sdk): surface json.Marshal errors in memory backend requests#679ardittirana wants to merge 1 commit into
Conversation
mustJSONReader discarded the json.Marshal error and returned a reader over a nil byte slice. When a value could not be serialized (unsupported type, cyclic struct, channel, func), the control-plane POST was sent with an empty body — silently storing nothing or overwriting with an empty value — and the real error never reached the caller. Replace it with jsonReader(v any) (io.Reader, error) and propagate the error at each call site (Set, Get, Delete, SetVector, SearchVector), all of which already return an error. Adds a test asserting an unserializable value yields an error instead of an empty reader. Fixes Agent-Field#434.
|
Thanks @ardittirana, this looks good. CLA is still pending. Can you sign it here? https://cla-assistant.io/Agent-Field/agentfield?pullRequest=679 Once that clears, we can continue. |
|
Signed 🫡 |
Performance
✓ No regressions detected |
📊 Coverage gateThresholds from
✅ Gate passedNo surface regressed past the allowed threshold and the aggregate stayed above the floor. |
📐 Patch coverage gateThreshold: 80% on lines this PR touches vs
❌ Patch gate failed
How to fix
|
|
Thanks for the review and approval, @santoshkumarradha — CLA's signed now, so it should be good to go. Appreciate the quick turnaround! |
|
Thanks for the follow-up. CLA is green now, but the branch is still blocked by the required The failing part is patch coverage on |
|
I rechecked this in a clean worktree. |
Fixes #434.
Problem
mustJSONReaderdiscarded thejson.Marshalerror:When a value can't be serialized (unsupported type, cyclic struct, channel, func),
json.Marshalreturnsnil, err, the error is dropped, and the function returns a reader over a nil slice. The downstream control-planePOSTis then sent with an empty body — silently storing nothing or overwriting with an empty value — and the real error never reaches the caller, making data-loss bugs in the memory backend very hard to debug.Fix
Replace it with
jsonReader(v any) (io.Reader, error)that returns the marshal error, and propagate that error at each of the five call sites (Set,Get,Delete,SetVector,SearchVector) — all of which already return anerror. No behavior change on the success path. Stdlib only.Test
Updates the existing helper test and adds a case asserting that an unserializable value (a channel) returns an error and a nil reader instead of silently yielding an empty body.
go test ./agent/passes (all existing backend tests included);gofmt/go vetclean.